const students = [
  {
    id: 161,
    name: "陈丽",
    sex: "女",
    address: "贵州省 黔南布依族苗族自治州 瓮安县",
    tel: "13523575728",
    age: 103,
  },
  {
    id: 162,
    name: "陈敏",
    sex: "男",
    address: "澳门特别行政区 澳门半岛 -",
    tel: "18932747951",
    age: 117,
  },
  {
    id: 163,
    name: "何强",
    sex: "女",
    address: "四川省 宜宾市 兴文县",
    tel: "13586865823",
    age: 57,
  },
  {
    id: 164,
    name: "董娜",
    sex: "男",
    address: "广西壮族自治区 贺州市 平桂管理区",
    tel: "18954361611",
    age: 97,
  },
  {
    id: 165,
    name: "黄磊",
    sex: "女",
    address: "浙江省 宁波市 其它区",
    tel: "13575483111",
    age: 37,
  },
  {
    id: 166,
    name: "姜秀英",
    sex: "男",
    address: "浙江省 衢州市 常山县",
    tel: "18982833522",
    age: 67,
  },
  {
    id: 167,
    name: "邹磊",
    sex: "男",
    address: "甘肃省 嘉峪关市 -",
    tel: "13523359243",
    age: 47,
  },
  {
    id: 168,
    name: "杨勇",
    sex: "女",
    address: "青海省 黄南藏族自治州 河南蒙古族自治县",
    tel: "18988942889",
    age: 44,
  },
  {
    id: 169,
    name: "沈军",
    sex: "男",
    address: "甘肃省 陇南市 武都区",
    tel: "13247448431",
    age: 97,
  },
  {
    id: 170,
    name: "萧静",
    sex: "女",
    address: "湖南省 张家界市 武陵源区",
    tel: "18941641358",
    age: 90,
  },
];

// 输出学生姓名
console.log(
  "输出学生姓名",
  students.map((o) => o.name)
);

// 得到所有女生
console.log(
  "得到所有女生",
  students.filter((v) => v.sex === "女")
);

// 25岁女生
console.log(
  "25岁女生",
  students.filter((v) => v.sex === "女" && v.age < 25)
);

// 陈姓学生
console.log(
  "陈姓学生",
  students.filter((v) => /^陈/.test(v.name))
);

// 电话号码以1结尾的学生
console.log(
  "电话号码以1结尾的学生",
  students.filter((v) => /1$/.test(v.tel))
);

// 得到所有女生姓名和电话号码
console.log(
  "得到所有女生姓名和电话号码",
  students
    .filter((v) => v.sex === "女")
    .map((o) => ({ name: o.name, tel: o.tel }))
);

// 学生年龄总和
console.log(
  "学生年龄总和：",
  students.reduce((pre, cur) => pre + cur.age, 0)
);

// 得到一个对象 { name: ['zs', 'ls'], age: [12,323] }
console.log(
  "对象映射",
  students.reduce((cur, pre) => {
    for (const key of Object.keys(pre)) {
      if (key === "id") continue;
      cur[key] = students.map((o) => o[key]);
    }
    return cur;
  }, {})
);

// 是否包含年龄大于28岁的男生
console.log(
  "是否包含年龄大于28岁的男生",
  students.filter((v) => v.sex === "男").find((o) => o.age > 28),
  students.filter((v) => v.sex === "男").some((v) => v.age > 28)
);

// 是否所有女生年龄都在28岁以内
console.log(
  "是否所有女生年龄都在28岁以内",
  students.filter((v) => v.sex === "女").every((v) => v.age < 28)
);
